﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StructureMap;
using StructureMap.Pipeline;
using StructureMap.Web.Pipeline;
using Library.Logging;
using Library.Structuremap;
using Core.Entities;
using Core.Dtos;

namespace Assembler
{ 
    /// <summary>
    /// Bootstrapper class is used to initialize the application on start
    /// </summary>
    public static class Bootstrapper
    {
        /// <summary>
        /// Amoung the initilization steps are : configure IoC library, configure AutoMapper
        /// </summary>
        /// <param name="useProxyServices"></param>
        /// <param name="ormContextLifecycle"></param>
        /// <param name="sessionLifecycle"></param>
        public static void Init(ILifecycle ormContextLifecycle, ILifecycle sessionLifecycle)
        {
            ObjectFactory.Initialize(x =>
            {
                x.For<CurrentContext>().LifecycleIs(sessionLifecycle);
                x.AddRegistry(new RepositoryRegistry(ormContextLifecycle));
                x.AddRegistry<GatewayRegistry>();
                x.AddRegistry<ServiceRegistry>();
            });

            AutoMapperConfig.CreateMappings();            
        }

        public static T Resolve<T>() where T : class
        {
            return (T)ObjectFactory.Container.TryGetInstance(typeof(T));
        }        
    }
}